using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Camalon.Drawing;

namespace Camalon.Drawing.Design
{
	/// <summary>
	/// Summary description for ShapeSelectorDialog.
	/// </summary>
	public class ShapeSelectorDialog : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ShapeSelectorDialog()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.PictureBox shapeImage;
		private System.Windows.Forms.ListBox shapeList;
		private System.Windows.Forms.Button button2;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.shapeImage = new System.Windows.Forms.PictureBox();
			this.shapeList = new System.Windows.Forms.ListBox();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button1.Location = new System.Drawing.Point(320, 229);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(90, 23);
			this.button1.TabIndex = 0;
			this.button1.Text = "OK";
			// 
			// button2
			// 
			this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button2.Location = new System.Drawing.Point(235, 229);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(80, 23);
			this.button2.TabIndex = 1;
			this.button2.Text = "Cancel";
			// 
			// shapeImage
			// 
			this.shapeImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.shapeImage.BackColor = System.Drawing.Color.White;
			this.shapeImage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.shapeImage.Location = new System.Drawing.Point(190, 0);
			this.shapeImage.Name = "shapeImage";
			this.shapeImage.Size = new System.Drawing.Size(220, 220);
			this.shapeImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
			this.shapeImage.TabIndex = 2;
			this.shapeImage.TabStop = false;
			// 
			// shapeList
			// 
			this.shapeList.Dock = System.Windows.Forms.DockStyle.Left;
			this.shapeList.Location = new System.Drawing.Point(0, 0);
			this.shapeList.Name = "shapeList";
			this.shapeList.Size = new System.Drawing.Size(190, 251);
			this.shapeList.TabIndex = 3;
			this.shapeList.SelectedIndexChanged += new System.EventHandler(this.shapeList_SelectedIndexChanged);
			// 
			// ShapeSelectorDialog
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(414, 259);
			this.Controls.Add(this.shapeList);
			this.Controls.Add(this.shapeImage);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "ShapeSelectorDialog";
			this.Text = "Select Shape";
			this.ResumeLayout(false);

		}
		#endregion


		public ShapeSelectorDialog(Camalon.Drawing.Shape[] shapes )
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			_shapes = shapes;
			if( shapes != null)
				foreach( Shape shape in shapes)
				
					this.shapeList.Items.Add( TypeDescriptor.GetComponentName( shape ));

		}
		
		Shape[] _shapes;
		Shape _selectedShape;

		[Browsable(false)]
		public Shape SelectedShape
		{
			get	{	return _selectedShape; }
		}

		private void shapeList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if( _shapes == null || _shapes.Length == 0) return;

			int  i = shapeList.SelectedIndex;
			if( i < 0 ) { shapeImage.Image = null; return;}

			Rectangle r = shapeImage.Bounds;
			r.Inflate( -6, -6 );

			Shape shape = _shapes[i];
			Bitmap bmp = shape.GetBitmap( );
			Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
			if( bmp.Width > r.Width || bmp.Height > r.Height)
				shapeImage.Image = bmp.GetThumbnailImage( r.Width, r.Height, myCallback, IntPtr.Zero);
			else shapeImage.Image = bmp;
			

			_selectedShape = shape;
		}
		public bool ThumbnailCallback()
		{
			return false;
		}
	



	}
}
